<template>
	<view>
		<u-calendar v-model="show" :mode="mode" @change="change" :mask-close-able="false">
				<view slot="tooltip">
					<view class="title">
						请选择住店/离店时间
					</view>
				</view>
			</u-calendar>
			 <mySignCalendar
			    ref="calendar"
			    :signData="signData"
			    :signList="signList"
			    @callbackSign="callbackSign"
			  >
			  </mySignCalendar>
			  <u-toast ref="uToast" />
			   <u-toast ref="uToasts" />
	</view>
</template>

<script>
	import mySignCalendar from '@/components/my-sign-calendar/my-sign-calendar'
	import {
		createNamespacedHelpers
	} from 'vuex';
	const {
		mapActions,
		mapState
	} = createNamespacedHelpers('user');
	export default {
		components:{
			mySignCalendar
		},
		created() {
			this.signList = Array
		},
		data() {
			return {
				show: false,
				mode: 'date',
				 signData: {
				    start: '2018-08-01', // 开始的日期（yyyy-mm-dd），默认‘2019-08-01’
				    ismake: true, // 是否开启补签
				    type: 'month' // 日历模式（月 => month，周 => week）
				  },
				    signList: [
				      { year: '2020', month: '3', day: '10'}
				    ]
			}
		},
		methods: {
			...mapActions(['changeUserIntegral']),
			change(e) {
				console.log(e);
				this.show=true
			},
			  // 签到回调
			 async callbackSign(data) {
			    console.log(data)
				const p=await this.changeUserIntegral({
					userIntegral:2,
					userIntergalType:"获取"
				})
				console.log("---------",p)
				if(p.code==10001){
					this.$refs.uToast.show({
										title: '签到失败,积分+2',
										type: 'success',
										
									})
				}else{
					this.$refs.uToasts.show({
										title: '签到失败',
										type: 'error',
										
									})
				}
			    // ajax请求，更新this.signList数据
			    // ajax请求成功，调用data.callback方法更新视图
			    data.callback && data.callback(data.data)
			    uni.showToast({
			      title: data.msg,
			      icon: 'none'
			    })
			  }
		}
	}
</script>

<style lang="scss" scoped>
	.title{
		color: $u-type-primary;
		text-align: center;
		padding: 20rpx 0 0 0;
	}
</style>
>
